package com.study.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 死循环——堆溢出
 * Created by hgg on 2021年9月30日11:23:32
 */
public class DeadWhile {

    private static ExecutorService fixedThreadPool = Executors.newFixedThreadPool(3);

    private static Object lock = new Object();

    public static void main(String[] args) {
        MyRunner my1 = new MyRunner();
        MyRunner my2 = new MyRunner();

        fixedThreadPool.execute(my1);
        fixedThreadPool.execute(my2);

        fixedThreadPool.shutdown();
    }


    static class MyRunner implements Runnable{
        @Override
        public void run() {
            synchronized (lock){
                Long i =1L;
                Boolean flag = true;
                Long start = System.currentTimeMillis();
                System.out.println(i + "：start：" + (start));
                while (flag){
                    i++;
                    if (i > 9999999999L){
                        flag = false;
                        System.out.println(i + "：over：" + (System.currentTimeMillis() - start));
                    }
                }
            }
        }
    }
}
